package itheima.moc.Testsocket;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Testreceive {
    public static void main(String[] args) throws IOException {
        //创建接收端对象  输入IP地址
        DatagramSocket ds = new DatagramSocket(11119);

        //用字节数组接收数据
        byte[] bytes = new byte[1024];
        //创建中转站 打包接收到的数据
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length);

        ds.receive(dp);

        int length = dp.getLength();
        System.out.println(new String(bytes,0,length));

        ds.close();
    }
}
